<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action {


	public function _initialize(){
		if (!ismobile()) {
			C('DEFAULT_THEME','Web');
		}

		$webconfig = $this->getWebConfig();
    $nav = $this->getNav();
		$banner = D('settings_banner')->order('sort asc')->limit($webconfig['bannernum'])->select();
		$bannerPc = D('banner_pc')->order('sort asc')->limit($webconfig['bannernum'])->select();

		$bannerBack = D('banner_back')->where('id=1')->select();

		// var_dump($bannerBack);
		// exit();

		$data = D('product')->select();
		$product = $data[0];

// 		var_dump($banner);
// 		exit();

		$links	= D('links')->where('status = 1')->select();
		$cid = $_GET['cid'];
		if(!$cid){
			$map = array('controller'=>MODULE_NAME,'function'=>ACTION_NAME);
			$cinfo = D('column')->where($map)->field('cid,title,pid')->find();
			$nid  = ($cinfo['pid'])?$cinfo['pid']:$cinfo['cid'];
		}

		$navinfo = array(
			'12'=>'合 作 共 赢',
			'13'=>'合 作 共 赢',
			'14'=>'合 作 共 赢',
			);

		$games = D('game')->order('sort asc')->select();

		// 获取栏目信息
		$columnInfo = $this->getColumnInfo();


		// echo "<pre>";
		// var_dump($columnInfo);
		// echo "</pre>";
		// exit();

		// 获取展示的视频
		$videos = $this->getShowVideos();

		$pcColumnInfo = $this->getPcColumnInfo();

		$this->assign('commendInfo', $this->getCommendColumnInfo());
		$this->assign('topInfo', $this->getTopColumnInfo());

		$this->assign('columnInfo', $columnInfo);
		$this->assign('videos', $videos);
		$this->assign('games', $games);
		$this->assign('navinfo',$navinfo[$cid]);
		$this->assign('nid',$nid);
		$this->assign('cid',$cinfo['cid']);
		$this->assign('cname',$cinfo['title']);
		$this->assign('banner',$banner);
		$this->assign('product',$product);
		$this->assign('nav',$nav);
		$this->assign('links',$links);
    	$this->assign('webconfig',$webconfig);
		$this->assign('bannerPc', $bannerPc);
		$this->assign('bannerBack', $bannerBack);
		$this->assign('pcColumnInfo', $pcColumnInfo);
		$this->assign('advantages', D("advantage")->select());
	}


    public function index(){

    	$cid_arr  = array(34,35,11,12,13,14,15,16,17,18);
    	$map1['cid'] = array('in',$cid_arr);
    	$map1['iscommend'] = 1;
    	$product = D('arclist')->where($map1)->order('sort asc')->select();
    	$faq = D('arclist')->where('cid = 36')->order('sort desc')->limit(8)->select();


    	$news1_top = D('arclist')->where('cid = 31 and iscommend = 1')->order('sendtime desc')->find();
    	$news1 = D('arclist')->where('cid = 31')->order('sendtime desc')->limit(8)->select();

    	$news2_top = D('arclist')->where('cid = 32 and iscommend = 1')->order('sendtime desc')->find();
    	$news2 = D('arclist')->where('cid = 32')->order('sendtime desc')->limit(8)->select();
    	$link = D('links')->order('lid asc')->limit(8)->select();

		$anli1     = D('arclist')->where('cid = 23')->order('id desc')->limit(6)->select();
		$anli2     = D('arclist')->where('cid = 25')->order('id desc')->limit(6)->select();
		$anli1_top = $anli1[0];
		$anli2_top = $anli2[0];
		unset($anli1[0]);
		unset($anli2[0]);

		$map = array('id' => 1);
        $res = D('about_us')->where($map)->select();
        $about = $res[0];
        $about['content'] = html_entity_decode($about['content']);
        if (mb_strlen($about['content']) > 220)
			$about['content'] = mb_substr($about['content'], 0, 220, 'utf-8') . "...";

		$this->assign('about', $about);

		$this->assign('nid','index');

		$this->assign('activeArr', $this->getNavActiveArr('indexActive'));

		$products = D('arclist')->where('cid=26')->order('sort asc')->limit(6)->select();

		$this->assign('products', $products);

		$news = D('arclist')->where('cid=25')->order('sort asc')->limit(4)->select();
		for ($i = 0; $i < count($news); $i++) {
			$news[$i]['year'] = date('Y/m', $news[$i]['updatetime']);
			$news[$i]['day'] = date('d', $news[$i]['updatetime']);
			$news[$i]['date'] = date('Y-m-d', $news[$i]['updatetime']);
		}

		$this->assign('news', $news);

    	$this->display();
	}

	protected function getNavActiveArr($activeKey) {
		$arr = array(
			'indexActive' => false,
			'aboutUsActive' => false,
			'productActive' => false,
			'newsActive' => false,
			'telUsActive' => false,
		);

		$arr[$activeKey] = true;
		return $arr;
	}

	public function column(){
	    // 打印当前url地址
// 	    echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
// 	    exit();

// 	    echo 'Here is column';
// 	    exit();

		$cid   = I('get.cid');
		$cinfo = D('column')->where('cid ='.$cid)->find();

		$cinfo['title'] = ($cid == 14 )?'信息安全责任书':$cinfo['title'];
		$navid = $cid;
		switch($cinfo['mid']){
			case 1: $countnum = 9;break;
			case 2: $countnum = 9;break;
			case 3: $countnum = 12;break;
			case 4: header('Location:'.U('Index/anli',array('cid'=>$cid)));
		}
		$address  = '<a href="'.U('Index/column',array('cid'=>$cinfo['cid'])).'">'.$cinfo['title'].'</a>';
		if($cinfo['pid']){
			$navid = $cinfo['pid'];
			$leftlist = D('column')->where('pid ='.$cinfo['pid'])->field('cid ,title,application,controller,function')->order('sort asc')->select();
			// 获取上级地址
		    $ttitle = D('column')->where('cid ='.$cinfo['pid'])->getField('title');
		    $turl   = U('Index/column',array('cid'=>$cinfo['pid']));
			$address  = '<a href="'.$turl.'">'.$ttitle.'</a>  / '.$address;
		}else{
			$leftlist = D('column')->where('pid ='.$cinfo['cid'])->order('sort asc')->field('cid ,title,application,controller,function')->select();
		}

		if(!$leftlist[0]){
			$mapcid = 1;
			$leftlist = D('column')->where('pid = 0')->order('sort asc')->field('cid ,title,application,controller,function')->select();
		}

		$cid_arr[] = $cid;
		foreach ($leftlist as $k => $v) {
			$url = $this->getNavUrl($v);
			$leftnav[] = array('title'=>$v['title'],'url'=>$url,'cid'=>$v['cid']);
			if(!$mapcid){
				$cid_arr[] = $v['cid'];
			}
		}

// 		var_dump($ttitle);
// 		exit();

		$this->assign('ttitle',$ttitle);
		$this->assign('address',$address);
		$this->assign('cinfo',$cinfo);
		$this->assign('leftnav',$leftnav);
		import('ORG.Util.Page');
		$map['cid']  = ($cinfo['pid'] == 0)?array('in',$cid_arr):$cid;
		$count   = D('arclist')->where($map)->count();
		$Page    = new Page($count,$countnum);

		// 新闻列表数据
		$list    = D('arclist')->where($map)->limit($Page->firstRow.','.$Page->listRows)->order('sort asc,updatetime desc')->select();

// 		echo '<pre>';
// 		var_dump($list);
// 		echo '</pre>';
// 		exit();

		// 单页显示字符串
		$show = $Page->show();

		foreach($list as $k => &$v){
			$v['url'] = U('content',array('id'=>$v['id']));
		}
		$this->assign('page',$show);


// 		var_dump($navid);
// 		exit();

		$this->assign('navid',$navid);
		$this->assign('list',$list);

		switch ($cinfo['mid']) {
			case '1':
			     $this->assign('body',$cinfo['pagecontent']);
			     $this->display('page');
			     break;
			case '2':
			     $this->display('newlist');
			     break;
			case '3':
			     $this->display('imglist');
			     break;
			default: echo '模型出错！'; break;
		}
	}


	public function content(){
		$map['id'] = I('get.id');
		$info  = D('arclist')->where($map)->find();
		$title = $info['title'];
		// echo $map['id'];
		// echo "<pre>";
		// var_dump($info);
		// echo "</pre>";
		// exit();

		$column = D('column')->where("cid = " . $info['cid'])->find();

		$this->assign('title', $column['title']);



	    //获取左侧同级列表和当前位置
		// $cinfo 	  = D('column')->where('cid ='.$info['cid'])->find();
		// $leftlist = D('column')->where('pid ='.$cinfo['pid'])->field('cid ,title')->select();
		//
		// if($cinfo['pid']){
		// 	$ttitle   = D('column')->where('cid ='.$cinfo['pid'])->getField('title');
		// }
	  //   $turl     = U('Index/column',array('cid'=>$cinfo['pid']));
	  //   $address  = ($ttitle)?'<a href="'.$turl.'">'.$ttitle.'</a> / ':'';
		//
	  //   $address .='<a href="'.U('Index/column',array('cid'=>$cinfo['cid'])).'">'.$cinfo['title'].'</a>';
	  //   foreach ($leftlist as $k => $v) {
		// 	$leftnav[] = array('title'=>$v['title'],'url'=>U('Index/column',array('cid'=>$v['cid'])));
		// }

		//根据对应模型获取 对应信息表和相关数据
		$modellist = D('model')->select();

		foreach($modellist as $k => $v){
			$model[$v['mid']] = $v;
		}
		$table  = $model[$info['mid']]['table'];

		$tpl  = $model[$info['mid']]['tpl'];
		$info2	= D($table)->where('aid = '.$map['id'])->find();
		$info   = array_merge($info,$info2);

		$this->assign('info', $info);

		// echo "<pre>";
		// var_dump($info);
		// echo "</pre>";
		// exit();



		// // 上一页下一页 数据
		// $front=D('arclist')->where("id <".$map['id']." and cid =".$info['cid'])->order('id desc')->limit('1')->field('title,id')->find();
		//
		// $after=D('arclist')->where("id >".$map['id']." and cid =".$info['cid'])->order('id desc')->limit('1')->field('title,id')->find();
		// $front['url'] 	=  $front['id']?U('Index/content',array('id'=>$front['id'])):'javascript:;';
		// $front['title'] =  $front['id']?$front['title']:'没有更多数据了！';
		// $after['url'] 	=  $after['id']?U('Index/content',array('id'=>$after['id'])):'javascript:;';
		// $after['title'] =  $after['id']?$after['title']:'没有更多数据了！';
		//
		// if($info['mid'] ==3){
		//
		// 	$imglist = D('arclist')->where(' id != '.$info['id'].' and cid = '.$info['cid'])->limit(4)->select();
		// 	$this->assign('imglist',$imglist);
		// 	$anlilist = D('arclist')->where('tid = '.$info['cid'])->limit(4)->select();
		// 	$this->assign('anlilist',$anlilist);
		//
		// }
		// $this->assign('address',$address);
		// $this->assign('leftnav',$leftnav);
		// $this->assign('front',$front);
		// $this->assign('after',$after);
		// $this->assign('info',$info);
		// $navid = $cinfo['pid']?$cinfo['pid']:$cinfo['cid'];
		// $this->assign('navid',$navid);
		// $this->display($tpl);
		$this->show();
	}

	// 疑难问题展示
	public function showAnswer()
	{
		$map['id'] = I('get.id');
		$info  = D('answer')->where($map)->find();

		// echo "<pre>";
		// var_dump($info);
		// echo "</pre>";
		// exit();
		$info['content'] = html_entity_decode($info['content']);
		$title = $info['title'];
		$this->assign('title', "疑难解答");

		$this->assign('info', $info);
		$this->display('content');
	}


	public function dolink(){
		if(session('verifycode') != md5($_POST['verify'])){
		   $this->error('验证码错误！',U('Index/link'));
		}

		$data = I('post.');
		if(!$data['title'] && !$data['url'] ){
			 $this->error('请正确填写信息！',U('Index/link'));
		}
		unset($data['verify']);
		$data['time']   = time();
		$data['status'] = 0;
		$data['sq'] = 1;
		$add= D('links')->add($data);
		if($add){
			$this->success('申请成功!',U('Index/link'));
		}else{
			$this->error('申请失败!',U('Index/link'));
		}
	}


	private function getWebConfig(){

		$webconfig = D('settings')->select();
		foreach($webconfig as $k => $v){
			$data[$v['key']] = $v['value'];
		}
		return $data;
	}


	private function getNav(){

		$info = D('column')->where('pid = 0')->order('sort asc')->select();
		foreach($info as $k => $v){
			$next = D('column')->where('pid = '.$v['cid'])->order('sort asc')->select();
			$nav[$v['cid']]['title']  = $v['title'];
			$nav[$v['cid']]['idname'] = $v['idname'];
			$nav[$v['cid']]['url'] 	  = $this->getNavUrl($v);
			$nav[$v['cid']]['class']  = ($next[0]['title'])?'dropdown':'';
			if($next){
				 foreach($next as $ks => $vs){
				 	$nav[$v['cid']]['next'][$vs['cid']]['title'] = $vs['title'];
				 	$nav[$v['cid']]['next'][$vs['cid']]['url'] =  $this->getNavUrl($vs);
				 }
			}
		}
		return $nav;
	}


	/**
	 * 获取每个栏目的信息
	 */
	private function getColumnInfo() {
	    $column = D('column')->where('pid = 0')->order('sort asc')->select();
	    $info = array();
	    foreach ($column as $k=>$v) {
	        $info[$v['cid']]['title'] = $v['title'];
	        // 设定查询列表的条件
	        $map['cid'] = $v['cid'];
	        // 获取前5条信息列表
	        $list = D('arclist')->where($map)->limit(5)->order('sort asc,updatetime desc')->select();
	        $arc = array();
	        foreach ($list as $lk=>$lv) {
	            $arc[$lv['id']]['cid'] = $lv['cid'];
	            $arc[$lv['id']]['mid'] = $lv['mid'];

							$title = $lv['title'];
							if (mb_strlen($title) > 12)
								$title = mb_substr($title, 0, 12, 'utf-8') . "...";

	            $arc[$lv['id']]['title'] = $title;
	            $arc[$lv['id']]['keyword'] = $lv['keyword'];
	            $arc[$lv['id']]['description'] = $lv['description'];
	            $arc[$lv['id']]['images'] = $lv['images'];
	            $arc[$lv['id']]['url'] = U('content', array('id'=>$lv['id']));
							$arc[$lv['id']]['updatetime'] = date('Y-m-d', $lv['updatetime']);
	        }
	        $info[$v['cid']]['arclist'] = $arc;
	    }
	    return $info;
	}

	private function getPcColumnInfo()
	{
		$list = D('arclist')->where('iscommend=0 and price=0')->limit(4)->order('sort asc,updatetime desc')->select();

		foreach($list as $k=>$v) {
			$title = $v['title'];
			if (mb_strlen($title, 'utf-8') > 15)
				$title = mb_substr($title, 0, 15, 'utf-8') . "...";
			$list[$k]['title'] = $title;
			$cid = $v['cid'];
			$column = D('column')->where('cid=' . $cid)->select();
			$list[$k]['column'] = $column[0]['title'];
			$list[$k]['url'] = U('content', array('id'=>$v['id']));
		}

		// echo '<pre>';
		// var_dump($list);
		// exit();

		return $list;
	}

	// 获取退浆的信息
	private function getCommendColumnInfo() {
		$data = D('arclist')->where('iscommend=1')->order('sort asc,updatetime desc')->select();
		$commendInfo = $data[0];
		$commendInfo['url'] = U('content', array('id'=>$commendInfo['id']));
		return $commendInfo;
	}

	// 获取置顶的信息
	private function getTopColumnInfo()
	{
		$data = D('arclist')->where('price=1')->order('sort asc,updatetime desc')->select();
		$topInfo = $data[0];
		$topInfo['url'] = U('content', array('id'=>$topInfo['id']));
		return $topInfo;
	}

	// 获取更多标题
	public function titlePage()
	{
		$cid = $_GET['cid'];
		$map = array('cid' => $cid);

		$column = D('column')->where($map)->find();
		// echo "<pre>";
		// var_dump($column);
		// echo "</pre>";
		// exit();

		$title = $column['title'];

		import('ORG.Util.Page');// 导入分页类
		$count = D('arclist')->where($map)->count();// 查询满足要求的总记录数
		$Page = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		$Page->setConfig('theme', "%upPage% %downPage% %first% %linkPage% %nextPage% %end%");
		$show = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$list = D('arclist')->where($map)->order('sort asc,updatetime desc')->limit($Page->firstRow.','.$Page->listRows)->select();

		$this->assign('title',$title);
		$this->assign('list',$list);// 赋值数据集
		$this->assign('page',$show);// 赋值分页输出

		$this->show();
	}

	public function answerTitle()
	{

		$title = "疑难解答";

		import('ORG.Util.Page');// 导入分页类
		$count = D('answer')->where($map)->count();// 查询满足要求的总记录数
		$Page = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
		$Page->setConfig('theme', "%upPage% %downPage% %first% %linkPage% %nextPage% %end%");
		$show = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$list = D('answer')->where($map)->order('sort asc')->limit($Page->firstRow.','.$Page->listRows)->select();

		$this->assign('title',$title);
		$this->assign('list',$list);// 赋值数据集
		$this->assign('page',$show);// 赋值分页输出
		$this->show();
	}

	// 视频展示页
	public function videoPage()
	{
		$title = "视频";

		import('ORG.Util.Page');// 导入分页类
		$count = D('video')->where($map)->count();// 查询满足要求的总记录数
		$Page = new Page($count,3);// 实例化分页类 传入总记录数和每页显示的记录数
		$Page->setConfig('theme', "%upPage% %downPage% %first% %linkPage% %nextPage% %end%");
		$show = $Page->show();// 分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$list = D('video')->where($map)->order('sort asc')->limit($Page->firstRow.','.$Page->listRows)->select();

		// echo "<pre>";
		// var_dump($list);
		// echo "</pre>";
		// exit();

		$this->assign('title', $title);
		$this->assign('list', $list);
		$this->assign('page', $show);
		$this->show();
	}


	// 获取展示的视频
	private function getShowVideos()
	{
		$videos = D('video')->limit(2)->order('sort asc')->select();
		return $videos;
	}


	private function getNavUrl($v){

	    // 如果function没有赋值，则给默认的U('Index/column',array('cid'=>$v['cid']))
		$url = $v['function']? U( $v['application'].'/'.$v['controller'].'/'.$v['function'] ):U('Index/column',array('cid'=>$v['cid']));

		$url = $v['url']?$v['url']:$url;
		return $url;
	}


	public function verify(){
		import('ORG.Util.Image');
        Image::buildImageVerify(5, 1, 'jpeg', '60', '25', 'verifycode');
    }


	public function apipage(){

		$id = I('get.id')?I('get.id'):1;


		$apileft = array(
			1=> array('name'=>'发送接口','url'=>U('Index/apipage',array('id'=>1))),
			2=> array('name'=>'余额及已发送量查询接口','url'=>U('Index/apipage',array('id'=>2))),
			3=> array('name'=>'非法关键词查询','url'=>U('Index/apipage',array('id'=>3))),
			4=> array('name'=>'状态报告接口','url'=>U('Index/apipage',array('id'=>4))),
			5=> array('name'=>'上行接口','url'=>U('Index/apipage',array('id'=>5))),
		);

		$apileft[$id]['class'] = 'on';
		$address = '<li>API接口</li><li>短信接口</li><li>'.$apileft[$id]['name'].'</li> ';
		$this->assign('address',$address);

		$this->assign('apileft',$apileft);
		$page = 'api_'.$id;
		$this->display($page);

	}

	public function doreg(){

		$info = I('post.');
		$json['status'] = 2;

		/*判断是否申请过*/
		$map['tel'] 	= $info['phone'];
		$is_has = D('message')->where($map)->find();
		if($is_has['mid']){
			$json['status'] = 2;
			$json['msg']	= '您已经申请过，请勿重复操作！';
			echo json_encode($json);
			return 0;
		}

		/*判断验证码是否超时或不存在*/
		$map['code']	= $info['check_num'];
		$code_time = D('code')->where($map)->order('id desc')->getField('time');
		if( !$code_time ){
			$json['msg']	= '验证码有误！';
			echo json_encode($json);
			return 0;
		}

		$now_time = time() - $code_time;
		if( $now_time >= 3600){
			$json['msg']	= '验证码已超时，请重新获取！'.$now_time;
			echo json_encode($json);
			return 0;
		}

		/*保存数据*/
		$data['name']  = $info['name'];
		$data['tel']   = $info['phone'];
		$data['company'] = $info['company_name'];
		$data['position'] = $info['position'];
		$data['time']	= time();

		$add = D('message')->add($data);
		if($add){
			$json['status'] = 1;
			echo json_encode($json);
		}else{
			$json['msg']	= '网站内部错误，请联系管理员！';
			echo json_encode($json);
		}
	}

	public function sms_cx(){

		$num  = 5;
		$list = array('政府','银行','房产','汽车','商超','企业');

		$this->assign('list',$list);
		$this->assign('num',$num);
		$this->display();
	}



	public function sendsms(){

		$map['tel'] = I('get.phone');
		$info = D('code')->where($map)->find();
		$now_time = time()-$info['time'];
		/* 判断是否生成过验证码  三种*/
		if( $now_time > 3600 ){
			$data['code'] = rand(100000,999999);
			$data['tel']  = $map['tel'];
			$data['time'] = time();
			D('code')->add($data);
			$code  = $data['code'];
		}else{
			$code = $info['code'];
		}

		$nums = $this->smsnum($map['tel']);
		if(!$nums){
			$data['msg'] = '验证发送超过3次，请明天再来！';

		}else{
			$send = $this->sendQXT($map['tel'],$code);
			if($send){
				$data['msg'] = '验证码已经发送到手机！';
				D('codenum')->where('tel = '.$mobile)->setInc('cnum');
			}else{
				$data['msg'] = '验证码发送失败，请联系管理员！';
			}
		}
		echo  json_encode($data);
	}

	// 发送验证码接口
	public function sendQXT($mobile,$code){
		$post_data = array();
		$post_data['userid']   = 26;
		$post_data['account']  = 'dqkjhy';
		$post_data['password'] = '15034046540';
		$post_data['content']  = '[企信通]您的验证码为：'.$code.',请勿泄露给他人！'; //短信内容
		$post_data['mobile']   = $mobile;
		$post_data['sendtime'] = ''; //时定时发送，输入格式YYYY-MM-DD HH:mm:ss的日期值
		/*$info  = '<?xml version="1.0" encoding="utf-8" ?><returnsms>
		 <returnstatus>Success</returnstatus>
		 <message>ok</message>
		 <remainpoint>4928</remainpoint>
		 <taskID>236</taskID>
		 <successCounts>1</successCounts></returnsms>';*/
		$info    = $this->dosendsms($post_data);
 		$info 	 = $this->xml_to_array($info);
		$status  = $info['returnsms']['returnstatus'];
 		if($status == 'Success'){
 			D('codenum')->where('tel = '.$mobile)->setInc('cnum');
 			return 1;
 		}else{
 			return 0;
 		}
	}

	public function jsms(){
		$mobile = I('post.mobile');
		$nums = $this->smsnum($mobile);
		if(!$nums){
			$data['msg'] = "今天的测试次数已经结束，请明天再来！";
			echo json_encode($data);
			exit;
		}
		$post_data = array();
		$post_data['userid']   = 26;
		$post_data['account']  = 'dqkjhy';
		$post_data['password'] = '15034046540';
		$post_data['content']  = '[企信通]感谢测试，具体业务咨询及办理，请联系24小时在线客服或直拨24小时客服电话：400-172-0351'; //短信内容
		//$post_data['content']  = '[企信通]您的验证码为：123654,请勿泄露给他人！'; //短信内容
		$post_data['mobile']   =  $mobile;
		$post_data['sendtime'] = ''; //时定时发送，输入格式YYYY-MM-DD HH:mm:ss的日期值
		$info    = $this->dosendsms($post_data);
 		$info 	 = $this->xml_to_array($info);
		$status  = $info['returnsms']['returnstatus'];
		$message = $info['returnsms']['message'];
 		if($status == 'Success'){
 			$data['msg'] = '发送成功！';
 			D('codenum')->where('tel = '.$mobile)->setInc('cnum');
 		}else{
 			$data['msg'] = $message;
 		}
 		echo json_encode($data);
	}


	// 查看当天是否超过次数
	private function smsnum($mobile){
		$map['tel'] = $mobile;
		$info  =  D('codenum')->where($map)->find();
		$notime = time() - $info['time'] ;
		if(!$info){
			$data['tel']  = $mobile;
			$data['cnum']  = 0 ;
			$data['time'] = time();
			D('codenum')->where($map)->add($data);
			return 1;
		}
		if( $notime < (3600*24) ){
			return ($info['cnum']<3)?1:0;
		}else{

			$data['cnum'] = 0 ;
			$data['time'] = time();
			D('codenum')->where($map)->save($data);
			return  1;
		}
	}

	private function dosendsms($post_data){

		$url='http://47.93.49.203:8888/sms.aspx?action=send';
		$o='';
		foreach ($post_data as $k=>$v)
		{
		   $o.="$k=".urlencode($v).'&';
		}
		$post_data=substr($o,0,-1);
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要将结果直接返回到变量里，那加上这句。
		return  $result = curl_exec($ch);
	}

	public  function xml_to_array($xml) {
	    $search = '/<(\w+)\s*?(?:[^\/>]*)\s*(?:\/>|>(.*?)<\/\s*?\\1\s*?>)/s';
	    $array = array ();
	    if(preg_match_all($search, $xml, $matches)){
	        foreach ($matches[1] as $i => $key) {
	            $value = $matches[2][$i];
	            if(preg_match_all($search, $value, $_matches)){
	                $array[$key] = $this->xml_to_array($value);
	            }else{
	                if('ITEM' == strtoupper($key)){
	                    $array[] = html_entity_decode($value);
	                }else{
	                    $array[$key] = html_entity_decode($value);
	                }
	            }
	        }
	    }
	    return $array;
	}

	// 游戏展示页
	public function gameshow()
	{
		$id = $_GET['id'];
		$map = array('id' => $id);
		$game = D('game')->where($map)->select();
		$data = $game[0];
		$title = $data['name'];

		$data['content'] = html_entity_decode($data['content'], ENT_QUOTES, 'UTF-8');
		// echo $title;
		// exit();

		// echo "<pre>";
		// var_dump($game);
		// echo "</pre>";
		// exit();
		$this->assign('title', $title);
		$this->assign('data', $data);
		$this->show();
	}

	// 新闻列表页面
	public function news()
	{
		$info = D('banner_back')->select();
		$banner = $info[0]['img'];
		$this->assign('banner', $banner);
		$this->assign('activeArr', $this->getNavActiveArr('newsActive'));
		$this->show();
	}

	public function getNewsPerPage()
	{
		$currentPage = $_GET['current'];
		$perPageNum = 5;
		$news = D('arclist')->where('cid=25')->order('sort asc')->limit(($currentPage-1)*$perPageNum, $perPageNum)->select();
		for ($i = 0; $i < count($news); $i++) {
			$news[$i]['year'] = date('Y', $news[$i]['updatetime']);
			$news[$i]['day'] = date('m/d', $news[$i]['updatetime']);
			$news[$i]['date'] = date("Y-m-d", $news[$i]['updatetime']);
		}
		echo json_encode($news);
	}

	public function getNewsTotlePageNum()
	{
		$perPageNum = 5;
		$newsCount = D('arclist')->where('cid=25')->count();
		$pageNum = ceil($newsCount/$perPageNum);
		$res = array('pageNum' => $pageNum);
		echo json_encode($res);
	}

	// 获取新闻页栏目信息
	private function getNewsColumnInfo() {
	    $column = D('column')->where('pid = 0')->order('sort asc')->select();
	    $info = array();
			$pageCount = 5;
	    foreach ($column as $k=>$v) {
	        $info[$v['cid']]['title'] = $v['title'];
	        // 设定查询列表的条件
	        $map['cid'] = $v['cid'];

					$count = D('arclist')->where($map)->count();
					$info[$v['cid']]['isHaveNext'] = $count > $pageCount ? 1 : 0;

	        // 获取前5条信息列表
	        $list = D('arclist')->where($map)->limit($pageCount)->order('sort asc,updatetime desc')->select();
	        $arc = array();
	        foreach ($list as $lk=>$lv) {
	            $arc[$lv['id']]['cid'] = $lv['cid'];
	            $arc[$lv['id']]['mid'] = $lv['mid'];

							$title = $lv['title'];
							if (mb_strlen($title) > 20)
								$title = mb_substr($title, 0, 20, 'utf-8') . "...";

	            $arc[$lv['id']]['title'] = $title;
	            $arc[$lv['id']]['keyword'] = $lv['keyword'];
	            $arc[$lv['id']]['description'] = $lv['description'];
	            $arc[$lv['id']]['images'] = $lv['images'];
	            $arc[$lv['id']]['url'] = U('content', array('id'=>$lv['id']));
							$arc[$lv['id']]['updatetime'] = date('Y-m-d', $lv['updatetime']);
	        }
	        $info[$v['cid']]['arclist'] = $arc;
	    }
	    return $info;
	}


		// ajax获取分页信息
    public function getPageInfo()
    {
      $columnId = $_POST['columnId'];
      $pageNum = $_POST['pageNum'];

      $numPerPage = 5;

      $map = array('cid' => $columnId);
      $count = D('arclist')->where($map)->count();

      $min = $numPerPage * ($pageNum - 1);
      // $max = ($numPerPage * $pageNum) > $count ? $count : ($numPerPage * $pageNum);
      $list = D('arclist')->where($map)->order('sort asc,updatetime desc')->limit($min.','.$numPerPage)->select();

      foreach ($list as $key => $value) {
        $title = $value['title'];
        if (mb_strlen($title) > 20)
          $title = mb_substr($title, 0, 20, 'utf-8') . "...";
        $list[$key]['title'] = $title;
        $list[$key]['url'] = U('content', array('id'=>$value['id']));
        $list[$key]['updatetime'] = date('Y-m-d', $value['updatetime']);
      }


      $isHaveNext = ($numPerPage * $pageNum) >= $count ? False : True;
      $isHavePre = $pageNum > 1 ? True : False;

      $data['list'] = $list;
      $data['isHaveNext'] = $isHaveNext;
      $data['isHavePre'] = $isHavePre;

      echo json_encode($data);
    }


		private function getVideoInfo()
		{
			return $this->getVideoPage(1, 6);
		}

		public function ajaxGetVideoPage()
		{
      $pageNum = $_POST['pageNum'];
			$videoInfo = $this->getVideoPage($pageNum, 6);
			echo json_encode($videoInfo);
		}

		private function getVideoPage($page, $numPerPage)
		{
			$count = D('video')->count();
			$min = ($page - 1) * $numPerPage;
			$list = D('video')->where($map)->order('sort asc')->limit($min.','.$numPerPage)->select();
			$info['list'] = $list;

			$isHaveNext = ($numPerPage * $page) >= $count ? 0 : 1;
      $isHavePre = $page > 1 ? 1 : 0;

			$info['isHaveNext'] = $isHaveNext;
			$info['isHavePre'] = $isHavePre;
			return $info;
		}


		public function about() {

			$map = array('id' => 1);
	        $res = D('about_us')->where($map)->select();
	        $about = $res[0];
	        $about['content'] = html_entity_decode($about['content']);

			$this->assign('about', $about);

			$this->assign('activeArr', $this->getNavActiveArr('aboutUsActive'));
			$this->show();
		}


		public function product() {
			$info = D('product')->select();
			$banner = $info[0]['img'];
			$this->assign('banner', $banner);
			$products = D('arclist')->where('cid=26')->order('sort asc')->select();
			$this->assign('products', $products);
			$this->assign('activeArr', $this->getNavActiveArr('productActive'));
			$this->show();
		}


		public function productPage()
		{
			$info = D('product')->select();
			$banner = $info[0]['img'];
			$productId = $_GET['id'];
			$product = D('arclist')->where('id='.$productId)->find();
			$content = D('arclist_news')->where('aid='.$productId)->find();
			$product['content'] = html_entity_decode($content['content']);
			$product['updatetime'] = date('Y-m-d', $product['updatetime']);

			$lastPro = D('arclist')->where("sort < ".$product['sort']." AND cid = 26")->order("sort desc")->find();
			$nextPro = D('arclist')->where("sort > ".$product['sort']." AND cid = 26")->order("sort asc")->find();

			$product['lastPro'] = $lastPro;
			$product['nextPro'] = $nextPro;

			$this->assign('banner', $banner);
			$this->assign('product', $product);
			$this->assign('activeArr', $this->getNavActiveArr('productActive'));
			$this->show();
		}


		public function newsPage()
		{
			$info = D('banner_back')->select();
			$banner = $info[0]['img'];
			$newsId = $_GET['id'];
			$news = D('arclist')->where('id='.$newsId)->find();
			$content = D('arclist_news')->where('aid='.$newsId)->find();
			$news['content'] = html_entity_decode($content['content']);
			$news['updatetime'] = date('Y-m-d', $news['updatetime']);

			$lastNews = D('arclist')->where("sort < ".$news['sort']." AND cid = 25")->order("sort desc")->find();
			$nextNews = D('arclist')->where("sort > ".$news['sort']." AND cid = 25")->order("sort asc")->find();

			$news['lastNews'] = $lastNews;
			$news['nextNews'] = $nextNews;

			$this->assign('banner', $banner);
			$this->assign('news', $news);
			$this->assign('activeArr', $this->getNavActiveArr('newsActive'));
			$this->show();
		}


		public function telus() {

			$banner = $this->getImg('telUsBanner');
			$this->assign('banner', $banner);
			
			$this->assign('activeArr', $this->getNavActiveArr('telUsActive'));
			$this->show();
		}


		public function recruit()
		{
			$categoryId = $_GET['categoryId'];
			$cityId = $_GET['cityId'];
			$searchStr = $_GET['searchStr'];

			$paramMap = array('categoryId' => $categoryId,
												'cityId' => $cityId,
												'searchStr' => $searchStr);

			$cityList = D('recruit_city')->order('sort asc')->select();
			foreach ($cityList as $key => $value) {
				$paramMap['cityId'] = $value['id'];
				if ($value['is_all'] == 1) {
					$paramMap['cityId'] = "";
				}
				$url = U('Index/recruit', $paramMap);
				$cityList[$key]['url'] = $url;
			}

			$paramMap['cityId'] = $cityId;	// 重新给cityId赋值,否则上面处理城市列表会覆盖cityId的值
			$categoryList = D('recruit_category')->order('sort asc')->select();
			foreach ($categoryList as $key => $value) {
				$paramMap['categoryId'] = $value['id'];
				if ($value['is_all'] == 1) {
					$paramMap['categoryId'] = "";
				}
				$url = U('Index/recruit', $paramMap);
				$categoryList[$key]['url'] = $url;
			}

			$map = array();
			if (!($categoryId == 0 || $categoryId == ""))
				$map['category_id'] = $categoryId;
			if (!($cityId == 0 || $cityId == ""))
				$map['city_id'] = $cityId;
			if ($searchStr != "") {
				$map['title'] = array('like', "%".$searchStr."%");
			}

			import('ORG.Util.Page');// 导入分页类
			$count = D('recruit')->where($map)->count();
			$Page = new Page($count,10);
			$Page->setConfig('theme', "%upPage% %downPage% %first% %linkPage% %nextPage% %end%");
			$show = $Page->show();// 分页显示输出
			$list = D('recruit')->where($map)->order('sort asc, updatetime desc')->limit($Page->firstRow.','.$Page->listRows)->select();

			foreach ($list as $key => $value) {
				$city = D('recruit_city')->where('id='.$value['city_id'])->select();
				$category = D('recruit_category')->where('id='.$value['category_id'])->select();
				$list[$key]['city'] = $city[0]['city'];
				$list[$key]['category'] = $category[0]['category'];
				$list[$key]['updatetime'] = date('Y-m-d', $value['updatetime']);
			}

			$this->assign('cityList', $cityList);
			$this->assign('categoryList', $categoryList);
			$this->assign('list', $list);
			$this->assign('searchStr', $searchStr);
			$this->assign('cityId', $cityId);
			$this->assign('categoryId', $categoryId);
			$this->assign('page',$show);

			// echo "<pre>";

			// echo $cityId;
			// echo $categoryId;

			// var_dump($map);
			// var_dump($cityList);
			// var_dump($categoryList);
			// var_dump($list);
			//
			// echo "</pre>";
			// exit();

			$this->show();
		}


	public function getImg($key)
    {
        $condition = array('key' => $key);
        $res = D('imgs')->where($condition)->find();
        $img = "";
        if ($res) {
            return $res['val'];
        }
        return $img;
    }





}
